//
//  MessagePushView.swift
//  Kosspot
//
//  Created by 李鑫 on 2025/7/14.
//

import SwiftUI
import Foundation
import UIKit

struct MessagePushView: View {
    @State private var isPhoneEnabled = false
    @State private var isMessageEnabled = false
    @State private var isQQEnabled = false
    @State private var isWeChatEnabled = false
    @State private var isOtherEnabled = false
    let message = "提示:打开某类别的消息推送开关，使该项的消息在手表上提醒，如果消息推送异常，可以重启通知使用权服务进行修复。"
    var body: some View {
        VStack {
            CustomNavigationBar(rightImageName:nil, title: "消息推送") {}
        
            ScrollView (.vertical,showsIndicators: false){
                MessageItemView(isEnabled: $isPhoneEnabled, titleImageName: "电话", title: "电话")
                Spacer().frame(height: 12)
                
                MessageItemView(isEnabled: $isMessageEnabled, titleImageName: "消息", title: "消息")
                Spacer().frame(height: 12)
                
                MessageItemView(isEnabled: $isQQEnabled, titleImageName: "QQ", title: "QQ")
                Spacer().frame(height: 12)
               
                MessageItemView(isEnabled: $isWeChatEnabled, titleImageName: "微信", title: "微信")
                Spacer().frame(height: 12)
              
                MessageItemView(isEnabled: $isOtherEnabled, titleImageName: "其他", title: "其他")
                Spacer().frame(height: 16)
                Text (.init(createAttributedString()))
                    .font(.system(size: 14))
                    .foregroundStyle(Color(hex: "#B2B2B2"))
                    .lineLimit(5)
                    .padding(.horizontal,24)
            }
            Spacer()
        }
        .navigationBarHidden(true)
        .background(Color(hex: "#0A0A0A"))
        .edgesIgnoringSafeArea(.all)
    }
    
    func createAttributedString() -> NSAttributedString {
            let attributedString = NSMutableAttributedString(string: message)
            if let range = message.range(of: "通知使用权") {
                let nsRange = NSRange(range, in: message)
                attributedString.addAttribute(
                    .foregroundColor,
                    value: Color(hex: "#00E9DA"),
                    range: nsRange
                )
            }
            return attributedString
        }
}


struct MessageItemView: View {
    @Binding var isEnabled: Bool
    let titleImageName: String
    let title: String
    var body: some View {
        HStack {
            Image(titleImageName)
                .resizable()
                .frame(width: 32,height: 32)
                .padding(.leading,20)
            
            Text(title)
                .font(.system(size: 16))
                .foregroundStyle(.white)
            Spacer()
            
            Toggle("", isOn: $isEnabled)
                .toggleStyle(SwitchToggleStyle(tint: Color(hex: "#00E9DA")))
                .frame(width: 47,height: 27)
                .padding(.trailing,20)
        }
        .frame(height: 56)
        .background(Color(hex: "#1E1E1E"))
        .cornerRadius(16)
        .padding(.horizontal,12)
    }
}













//
//#Preview {
//    MessagePushView()
//}
